home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / unix / mp14tar.z / mp14tar / mpack / string.c < prev    next >
C/C++ Source or Header  |  1994-06-01  |  3KB  |  81 lines

  1. /*
  2.  * String manipulation routines
  3.  */
  4. /* (C) Copyright 1993 by John G. Myers
  5.  * All Rights Reserved.
  6.  *
  7.  * Permission to use, copy, modify, distribute, and sell this software
  8.  * and its documentation for any purpose is hereby granted without
  9.  * fee, provided that the above copyright notice appear in all copies
  10.  * and that both that copyright notice and this permission notice
  11.  * appear in supporting documentation, and that the name of John G.
  12.  * Myers not be used in advertising or publicity pertaining to
  13.  * distribution of the software without specific, written prior
  14.  * permission.  John G. Myers makes no representations about the
  15.  * suitability of this software for any purpose.  It is provided "as
  16.  * is" without express or implied warranty.
  17.  *
  18.  * JOHN G. MYERS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  19.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  20.  * FITNESS, IN NO EVENT SHALL JOHN G. MYERS BE LIABLE FOR ANY SPECIAL,
  21.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  22.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  23.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
  24.  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  25.  */
  26.  
  27. #include <ctype.h>
  28.  
  29. static unsigned char upcase[256] = {
  30.     0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
  31.    16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  32.   ' ','!','"','#','$','%','&', 39,'(',')','*','+',',','-','.','/',
  33.   '0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?',
  34.   '@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
  35.   'P','Q','R','S','T','U','V','W','X','Y','Z','[', 92,']','^','_',
  36.   '`','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
  37.   'P','Q','R','S','T','U','V','W','X','Y','Z','{','|','}','~',127,
  38.   128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
  39.   144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
  40.   160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
  41.   176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
  42.   192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
  43.   208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
  44.   224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
  45.   240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255};
  46.  
  47. #define UPC(x) (upcase[(unsigned char)(x)])
  48.  
  49. /*
  50.  * Same as strcmp, but case-insensitive.
  51.  */
  52. int
  53. cistrcmp(s1,s2)
  54. register char *s1,*s2;
  55. {
  56.     register char c1;
  57.     while ((c1 = *s1) && UPC(c1) == UPC(*s2)) {
  58.     s1++;
  59.     s2++;
  60.     }
  61.     return UPC(c1) - UPC(*s2);
  62. }
  63.  
  64. /*
  65.  * Same as strncmp, but case-insensitive.
  66.  */
  67. int
  68. cistrncmp(s1,s2,n)
  69. register char *s1,*s2;
  70. int n;
  71. {
  72.     register char c1;
  73.     while (n-- && (c1 = *s1) && UPC(c1) == UPC(*s2)) {
  74.     s1++;
  75.     s2++;
  76.     }
  77.     if (n == -1) return 0;
  78.     return UPC(c1) - UPC(*s2);
  79. }
  80.  
  81.